from pydantic import BaseModel, Field
from datetime import datetime
from typing import List, Optional, Dict, Any


class DocumentResponse(BaseModel):
    id: int = Field(..., description="文档ID")
    doc_name: str = Field(..., description="文档名称")
    doc_hash: str = Field(..., description="文档哈希值")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")
    vector_count: int = Field(..., description="向量数量")
    embedding_model_name: Optional[str] = Field(None, description="嵌入模型名称")
    chunk_mode: Optional[str] = Field(None, description="分块模式")
    chunk_params: Optional[Dict[str, Any]] = Field(None, description="分块参数")
    is_enabled: bool = Field(True, description="是否启用参与召回")


class DocumentListResponse(BaseModel):
    success: bool = Field(..., description="请求是否成功")
    documents: List[DocumentResponse] = Field(..., description="文档列表")
    total_count: int = Field(..., description="文档总数")
    page: int = Field(..., description="当前页码")
    page_size: int = Field(..., description="每页数量")
    total_pages: int = Field(..., description="总页数")


class BatchUploadRespons(BaseModel):
    doc_id: int = Field(..., description="文档ID")
    doc_name: str = Field(..., description="文档名称")
    vector_count: int = Field(..., description="生成的向量数量")


class BatchUploadResponse(BaseModel):
    success: bool = Field(..., description="上传是否成功")
    message: str = Field(..., description="响应消息")
    results: List[BatchUploadRespons] = Field(..., description="上传结果列表")
    total_documents: int = Field(..., description="处理的文档总数")


class ChunkResponse(BaseModel):
    chunk_index: int
    chunk_text: str


class ChunkListResponse(BaseModel):
    success: bool
    chunks: List[ChunkResponse]
    total_count: int
    page: int
    page_size: int
    total_pages: int


class DocumentUpdateRequest(BaseModel):
    doc_name: Optional[str] = Field(None, description="新的文档名称", min_length=1, max_length=255)
    is_enabled: Optional[bool] = Field(None, description="是否启用参与召回")


class ChunkUpdateRequest(BaseModel):
    chunk_text: str = Field(..., description="新的分块内容", min_length=1)


